﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define MAX 3
struct erwei
{
	int as;
	int hang;
	int lie;
	struct erwei* next;
};
struct erwei* creatnode()
{
	struct erwei* p = (struct erwei*)malloc(sizeof(struct erwei));
	p->next = NULL;
	p->hang = 0;
	p->lie = 0;
	return p;
}
struct erwei* pushNode(struct erwei* s, int bs)
{
	struct erwei* new = creatnode();
	s->next = new;
	new->as = bs;

	return s->next;
}
void Nodeprint(struct erwei* w)
{
	struct erwei* ws = w->next;
	while (ws != NULL)
	{
		printf("%d ", ws->as);
		ws = ws->next;
	}
}
int ZSUM(struct erwei* L)
{
	int sum = 0;
	struct erwei* l = L->next;
	while (l != NULL)
	{
		if (l->hang == l->lie)
		{
			sum += l->as;
		}
		l = l->next;
	}
	return sum;
}
int CSUM(struct erwei* ps)
{
	int sum = 0;
	struct erwei* l = ps->next;
	while (l != NULL)
	{
		if (l->hang + l->lie == MAX - 1)
		{
			sum += l->as;
		}
		l = l->next;
	}
	return sum;
}
void HL(struct erwei* hl)
{
	struct erwei* H = hl->next;
	while (H->next != NULL)
	{

		if (H->lie == MAX - 1)
		{
			H->next->hang = H->hang + 1;
			H->next->lie = 0;
		}
		else
		{
			H->next->lie = H->lie + 1;
			H->next->hang = H->hang;
		}
		H = H->next;
	}
}


int main()
{
	struct erwei* ps = creatnode();
	struct erwei* ts = ps;
	int b = 0;
	for (int i = 0; i < MAX * MAX; i++)
	{
		scanf("%d", &b);
		ts = pushNode(ts, b);
	}
	HL(ps);
	int sum = ZSUM(ps);
	printf("主对角线：%d\n", sum);
	int sums = CSUM(ps);
	printf("次对角线：%d\n", sums);
	return 0;
}